local Class = require('lua.lang.Class')

--- @class BasicBlock : Class
--- @field instructions Instruction[]
local BasicBlock = Class {}

--- @param instructions Instruction[]
--- @return BasicBlock
function BasicBlock:new(instructions)
	--- @type BasicBlock
	local o = {}
	o.instructions = instructions or {}
	return setmetatable(o, BasicBlock)
end

--- @return Instruction
function BasicBlock:getEntryInstruction()
	return self.instructions[1]
end

--- @return Instruction
function BasicBlock:getExitInstruction()
	local instructions = self.instructions
	return instructions[#instructions]
end

--- @param instruction Instruction
--- @return BasicBlock
function BasicBlock:addInstruction(instruction)
	local instructions = self.instructions
	instructions[#instructions + 1] = instruction
	return self
end

return BasicBlock